package exception;

import java.awt.*;

public class ThrowDemo {

        public static void main(String[] args) {
            try {
                validateAge(-5);
            } catch (IllegalArgumentException e) {
                System.out.println("捕获到异常: " + e.getMessage());
            }
        }

        public static void validateAge(int age) {
            if (age < 0) {
                throw new IllegalArgumentException("年龄不能为负数");
            }
            System.out.println("年龄合法: " + age);
        }
    }

